<!--
        File        : DatabaseContent.xsl
        Created     : 12.6.2014
        Author      : Martin Ribarič
        Description : XSLT script for transformation
-->
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

    <xsl:template match="videolibrary">
        <table id="outer">
            <thead>
                <tr>
                    <th style="text-align: center;">Category</th>
                    <th style="text-align: center;">Mediums</th>
                </tr>
            </thead>
            <xsl:apply-templates select="category"/>
        </table>
    </xsl:template>

    <xsl:template match="category">
        <tr>
            <td style="text-align: center;">
                <xsl:value-of select="@name"/>
            </td>
            <td>
                <xsl:choose>
                    <xsl:when test=".//medium">
                        <!--Fill whole space in outer table !!!!-->
                        <table id="inner">
                            <xsl:apply-templates select="mediums"/>
                        </table>
                    </xsl:when>
                    <xsl:otherwise>
                        <p>Empty category</p>
                    </xsl:otherwise>
                </xsl:choose>
            </td>
        </tr>
    </xsl:template>

    <xsl:template match="mediums">
        <xsl:for-each select="medium">
            <tr>
                <td>
                    <xsl:value-of select="@label"/> [<xsl:value-of select="@type"/>]
                </td>
                <td>
                    <table id="movies">
                        <xsl:apply-templates select="movies"/>
                    </table>
                </td>
            </tr>
        </xsl:for-each>
    </xsl:template>

    <xsl:template match="movies">
        <xsl:for-each select="movie">
            <tr>
                <td>
                    <xsl:value-of select="."/>
                </td>
            </tr>
        </xsl:for-each>
    </xsl:template>
</xsl:transform>



